<html>

<head>

    <meta charset="utf-8"/>

    <title>go测试socket</title>
    <script type="text/javascript">

        var sock = null;

        var wsuri = "ws://127.0.0.1:1234/websocket";

        window.onload = function() {

            logs();

            console.log("onload");

            sock = new WebSocket(wsuri);

            sock.onopen = function() {

                console.log("connected to " + wsuri);

            }

            sock.onclose = function(e) {


                console.log("connection closed (" + e.code + ")");

            }

            sock.onmessage = function(e) {
                
                document.getElementById('ms').innerText= e.data;

            }

        };
        function logs(){
            sock = new WebSocket("ws://127.0.0.1:1234/log");

            sock.onopen = function() {

                console.log("connected");

            }

            sock.onclose = function(e) {


                console.log("connection closed (" + e.code + ")");

            }

            sock.onmessage = function(e) {
                
                document.getElementById('log').innerText= e.data;

            }
        };
        function send() {

            var msg = document.getElementById('message').value;

            sock.send(msg);

        };

    </script>
</head>

<body>

    

    <h1>WebSocket Echo Test</h1>

    <form>

        <p>

            Message: <input id="message" type="text" value="Hello, world!">

        </p>

    </form>

    <button onclick="send();">Send Message</button>
    <div id ="ms" style="margin-top:10%"></div>
    <div id = "log"></div>
</body>

</html>